-- lab
-- create by cheny3
-- 死灵实验台

return {
    -- 判断
    canTrigger = function(args)
        -- 找一下当前有没有实验台
        for pos = 1, GRID_SIZE do
            local grid = DungeonM.getGridByPos(pos);
            if grid.type == GRID_TYPE_LAB then
                return true;
            end
        end
        return false;
    end,

    -- 触发
    trigger = function(args)
        -- 获取实验台格子
        local labGrid;
        local labPos;
        for pos = 1, GRID_SIZE do
            local grid = DungeonM.getGridByPos(pos);
            if grid.type == GRID_TYPE_LAB then
                labGrid = grid;
                labPos = pos;
                break;
            end
        end

        if not labGrid then
            return false;
        end

        -- 实验台操作
        local labId = labGrid.labId;
        local labInfo = DungeonLabM.query(labId);
        if not labInfo then
            error("获取实验台配置失败。");
            return false;
        end

        local classId = labInfo["class_id"];
        local ownId = DungeonLabM.getCurEquipId(classId);
        if not EquipM.isEquipment(classId) or not ownId then
            -- 不是装备或者还没有装备
            return DungeonActionM.go("lab_compound_item", labPos);
        end

        -- 尝试升级
        return DungeonActionM.go("lab_upgrade_equip", labPos);
    end,
};
